package com.beiing.tianshuai.tianshuai.home.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.IndexSearchListBean;
import com.beiing.tianshuai.tianshuai.entity.TopSearchAndClassificationBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LZQ on 2017/12/8.
 */

public class SearchModelImpl implements ISearchModel {

    @Override
    public void getTopSearchAndClassification(final CallBack<TopSearchAndClassificationBean> callBack) {
        DisposableObserver<TopSearchAndClassificationBean> observer = new DisposableObserver<TopSearchAndClassificationBean>() {
            @Override
            public void onNext(TopSearchAndClassificationBean bean) {
                callBack.result(bean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getTopSearchAndClassification()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void getSearchResult(String title, int typeId, final CallBack<IndexSearchListBean> callBack) {
        DisposableObserver<IndexSearchListBean> observer = new DisposableObserver<IndexSearchListBean>() {
            @Override
            public void onNext(IndexSearchListBean searchResultBean) {
                callBack.result(searchResultBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getSearchResult(title, typeId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
